package com.gao.e_topic;

import com.gao.App;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.concurrent.TimeUnit;

/**
 * @author gao
 * @time 2022/07/05 11:14:30
 */
@SpringBootTest(classes = App.class)
@RunWith(SpringRunner.class)
public class Producer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    public void test() throws InterruptedException {
        String[] messages = {"喵喵", "汪汪", "吱吱"};
        String[] routingKeys = {"lazy.black.cat", "quick.orange.dog", "quick.white.rabbit"};
        for (int i = 0; i < routingKeys.length; i++) {
            rabbitTemplate.convertAndSend("topic_logs", routingKeys[i], messages[i]);
        }

        TimeUnit.SECONDS.sleep(300);
    }
}
